package filter

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

func Error(r *ghttp.Request) {
	r.Middleware.Next()
	if err := r.GetError(); err != nil {
		// 记录到自定义错误日志文件
		g.Log("exception").Error(r.Context(), err)
		//返回固定的友好信息
		r.Response.ClearBuffer()
		r.Response.WriteJsonExit(&ghttp.DefaultHandlerResponse{
			Code:    500,
			Message: err.Error(),
		})
	}
}
